feat/validate video type before uploading to S3#1897
Merged
DavidsonGomes merged 4 commits intoEvolutionAPI:developfrom Sep 17, 2025
Merged
Conversation
Contributor
Reviewer's GuideThis PR introduces a new SAVE_VIDEO flag to the S3 configuration and updates message handling and upload paths to detect and skip video uploads when this flag is disabled, along with minor formatting cleanups. Sequence diagram for video upload validation before S3 uploadsequenceDiagram
participant Service as BaileysStartupService/BusinessStartupService
participant Config as ConfigService
participant S3 as S3
participant S3Bucket as S3 Bucket
Service->>Config: get<S3>("S3")
Config-->>Service: S3 config (ENABLE, SAVE_VIDEO)
Service->>Service: Check if message is video
alt SAVE_VIDEO is false and message is video
Service->>Service: Throw error 'Video upload is disabled.'
else SAVE_VIDEO is true or not video
Service->>S3Bucket: Upload media
end
Class diagram for updated S3 configuration and message handlingclassDiagram
class ConfigService {
+get<S3>(key: string): S3
...
}
class S3 {
ENABLE: boolean
SAVE_VIDEO: boolean
...
}
ConfigService --> S3
class BaileysStartupService {
+handleReceivedMessage(received)
+handleSentMessage(messageSent)
...
}
BaileysStartupService --> ConfigService
class BusinessStartupService {
+uploadMedia(result)
...
}
BusinessStartupService --> ConfigService
class getTypeMessage {
+getTypeMessage(msg)
}
getTypeMessage --> ConfigService
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The
if (isVideo && !SAVE_VIDEO)block is repeated in multiple places; consider extracting that logic into a shared helper or middleware to DRY up the upload flow. - The conditional logic in getConversationMessage around SAVE_VIDEO and media types is becoming complex—refactor or simplify it into smaller functions for readability and easier maintenance.
- Instead of throwing a generic Error when video uploads are disabled, use a custom error class or error code so downstream logic can handle this case more explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `if (isVideo && !SAVE_VIDEO)` block is repeated in multiple places; consider extracting that logic into a shared helper or middleware to DRY up the upload flow.
- The conditional logic in getConversationMessage around SAVE_VIDEO and media types is becoming complex—refactor or simplify it into smaller functions for readability and easier maintenance.
- Instead of throwing a generic Error when video uploads are disabled, use a custom error class or error code so downstream logic can handle this case more explicitly.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:1263` </location>
<code_context>
if (isMedia) {
if (this.configService.get<S3>('S3').ENABLE) {
try {
+ if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
+ throw new Error('Video upload is disabled.');
+ }
+
</code_context>
<issue_to_address>
Throwing an error for disabled video upload may disrupt flow.
Instead of raising an exception, consider skipping video uploads and logging a warning to prevent service interruption for other media types.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
=======
if (isVideo && !this.configService.get<S3>('S3').SAVE_VIDEO) {
this.logger.warn('Video upload is disabled. Skipping video upload.');
// Skip video upload by returning early from this block
return;
}
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `src/api/integrations/channel/meta/whatsapp.business.service.ts:462` </location>
<code_context>
mediaType = 'video';
}
+ if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
+ throw new Error('Video upload is disabled.');
+ }
+
</code_context>
<issue_to_address>
Error thrown for disabled video upload may affect user experience.
Instead of raising an exception, consider returning a user-friendly message or logging the event to avoid disrupting the user experience.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
throw new Error('Video upload is disabled.');
}
=======
if (mediaType == 'video' && !this.configService.get<S3>('S3').SAVE_VIDEO) {
this.logger?.info?.('Video upload attempted but is disabled by configuration.');
return {
success: false,
message: 'Video upload is currently disabled. Please contact support if you need this feature enabled.',
};
}
>>>>>>> REPLACE
</suggested_fix>
### Comment 3
<location> `src/config/env.config.ts:285` </location>
<code_context>
USE_SSL?: boolean;
REGION?: string;
SKIP_POLICY?: boolean;
+ SAVE_VIDEO: boolean;
};
</code_context>
<issue_to_address>
SAVE_VIDEO type should be optional for consistency.
Marking SAVE_VIDEO as optional aligns with the other S3 config properties and helps prevent issues with undefined values.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
SAVE_VIDEO: boolean;
=======
SAVE_VIDEO?: boolean;
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Collaborator
|
Please fix the lint with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Introduce a new SAVE_VIDEO configuration flag to prevent unnecessary S3 uploads for video messages when disabled, and enforce this check across message handling services and utilities.
New Features:
Enhancements: